# -*- coding: utf-8 -*-
"""\
cSAXS data preparation script, new flavor.
"""
import sys

first_scan = 512
scans = [512,513,862,863,1140,1141,1352,1353,
1508,1509,1622,1623,1722,1723]

import ptycho2 as ptycho
import numpy as np

# Need to "hack" the defaults for continuous scans
ptycho.cSAXS.FILENAME_PATTERN = '{read_path}/{prefix}{scan_number:05d}_{index}_00000.{file_extension}'

# Empty parameter structure
p = ptycho.Param()

p.verbose_level = 3
p.interactive = False                         # Not used for now
#p.base_path = '/home/philipp/Documents/master'
p.base_path = '/afs/psi.ch/user/b/braun_p/data/'
p.user = 'e14438'
#p.scan_number = 300 
p.dpsize = (192,192)                          # Crop size (used to be "asize")
p.ctr = (309, 263)                               # Center of cropped array
p.motors = ('py', 'px')                      # Motor names in y and x
p.motors_multiplier = 1e-3                    # Multiplier to convert motor values to meters
p.energy = 6.2                                # Energy in keV
p.detector_pixel_size = 172e-6                # Detector pixel size
p.detector_distance = 7.2122                    # Detector distance
p.scan_type = None#'raster'                            # None (use spec), or 'raster', 'round', 'round_ROI'


#p.scan_params.nx = 200
#p.scan_params.ny = 0
#p.scan_params.step_size_x = .02e-6
#p.scan_params.step_size_y = .5e-6

for s in scans:
	#specinfo = ptycho.cSAXS.spec.SpecInfo(p.base_path + '/specES1/dat-files/specES1_started_2013_03_20_1108.dat')
	specinfo = ptycho.cSAXS.spec.SpecInfo(p.base_path + '/specES1/dat-files/specES1_started_2013_03_16_1319.dat')
	#specinfo = ptycho.cSAXS.spec.SpecInfo('/home/philipp/Documents/master/specES1/dat-files/specES1_started_2013_03_16_1319.dat')
	p.spec_filename = specinfo

	p.scan_number = s
	ptycho.cSAXS.prepare_data(p)
